package com.ease.component.controls {

   import com.ease.component.controls.datagridclass.CheckBoxDataGridColumn;

   import mx.controls.AdvancedDataGrid;
   import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
   import mx.controls.listClasses.IListItemRenderer;
   import mx.core.ClassFactory;
   import mx.core.IFactory;
   import mx.core.mx_internal;

   use namespace mx_internal;

   [Event(name="selectChanged", type="flash.events.Event")]

   public class CheckBoxAdvancedDataGrid extends AdvancedDataGridEx {
      public function CheckBoxAdvancedDataGrid() {
         this.allowMultipleSelection = true;
         super();		 
		 this.setStyle("alternatingItemColors",[0xFFFFFF, 0xFAFAFA]);
      }

      private var _userColumns:Array;

      private var _checkBoxHeaderItemRenderer:IFactory;
      /**
       *  The class factory that will be used to create the header of checkbox column.
       */
      public function get checkBoxHeaderItemRenderer():IFactory {
         return _checkBoxHeaderItemRenderer;
      }
      public function set checkBoxHeaderItemRenderer(value:IFactory):void {
         _checkBoxHeaderItemRenderer = value;
         this.columns = _userColumns;
      }

      public var headerCheckBoxEnabled:Boolean = true;
      public function get userColumns():Array {
         return _userColumns;
      }

      override public function set columns(value:Array):void {
         _userColumns = value;
         var columns:Array = value.concat();
         var chkBoxClmn:CheckBoxDataGridColumn = new CheckBoxDataGridColumn();
         chkBoxClmn.headerRenderer = checkBoxHeaderItemRenderer;
         columns.splice(0, 0, chkBoxClmn);
         super.columns = columns;
      }

      override protected function selectItem(item:IListItemRenderer,
                                             shiftKey:Boolean,
                                             ctrlKey:Boolean,
                                             transition:Boolean=true):Boolean {
         if (isItemSelected(item.data)) {
            ctrlKey = true;
         }
         return super.selectItem(item, shiftKey, ctrlKey, transition);
      }

//      override protected function drawItem(item:IListItemRenderer,
//                                           selected:Boolean=false,
//                                           highlighted:Boolean=false,
//                                           caret:Boolean=false,
//                                           transition:Boolean=false):void {
//         super.drawItem(item, false, highlighted, caret, transition);
//      }
   }
}
